package cn.fl.audit.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.condition.AudCreditPassOpinionQueryCondition;
import cn.fl.audit.constant.AudStandingBookConstant;
import cn.fl.audit.dto.AudCreditExtInfoDTO;
import cn.fl.audit.dto.AudCreditPassOpinionDTO;
import cn.fl.audit.service.IAudCreditPassOpinionService;
import cn.fl.audit.service.IAuditApiService;
import cn.fl.audit.transform.AudCreditPassOpinionVOTransform;
import cn.fl.audit.vo.AudCreditExtInfoVO;
import cn.fl.audit.vo.AudCreditPassOpinionVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.customer.vo.CstCorpBscInfoVO;
import cn.fl.customer.vo.CstNpBscInfoVO;
import cn.fl.customer.vo.CstNpSocialRlVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.condition.PrjCstBscInfoQueryCondition;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsFeeQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsQueryCondition;
import cn.fl.project.constant.PrjCstBscInfoConstant;
import cn.fl.project.constant.PrjQuatPrpsFeeConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstBscInfoService;
import cn.fl.project.service.IPrjPrdBscInfoService;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjQuatPrpsFeeService;
import cn.fl.project.service.IPrjQuatPrpsService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstBscInfoVO;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.project.vo.PrjQuatPrpsFeeVO;
import cn.fl.project.vo.PrjQuatPrpsVO;
import fl.customer.facade.customer.constant.CustomerConstant;

/**
 * @Description: 信审通过意见 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AudCreditPassOpinionServiceImpl implements IAudCreditPassOpinionService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(AudCreditPassOpinionServiceImpl.class);
	
	/**
	 * 
	 */
	@Autowired
	private IAuditApiService auditApiService;
	
	/**
	 * 本地数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	/**
	 * 项目信息服务
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	
	/**
	 * 项目客户信息查询服务
	 */
	@Autowired
	private IPrjCstBscInfoService prjCstBscInfoService;
	
	/**
	 * 客户基础信息服务
	 */
	@Autowired
	private ICstBscInfoService cstBscInfoService;
	
	/**
	 * 项目报价方案信息服务
	 */
	@Autowired
	private IPrjQuatPrpsService prjQuatPrpsService;
	
	/**
	 * 项目费用信息服务
	 */
	@Autowired
	private IPrjQuatPrpsFeeService prjQuatPrpsFeeService;
	
	/**
	 * 项目产品明细服务
	 */
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;
	
	/**
	 * 项目产品基础服务
	 */
	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;

	@Override
	public AudCreditPassOpinionVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudCreditPassOpinionDTO dto = null;//this.自定义ApiService.selectById(id);
		return AudCreditPassOpinionVOTransform.toVO(dto);
	}

	@Override
	public Long add(AudCreditPassOpinionVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.auditApiService.addAudCreditPassOpinion(AudCreditPassOpinionVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.audCreditPassOpinionApiService.removeById(id);
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(AudCreditPassOpinionVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.auditApiService.modifyAudCreditPassOpinion(AudCreditPassOpinionVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.audCreditPassOpinionApiService.searchListPage(page);
		return null;
	}

	@Override
	public AudCreditPassOpinionVO selectAudCreditPassOpinionByQc(AudCreditPassOpinionQueryCondition qc) throws BaseException {
		if(null==qc || null==qc.getProjectId() || StringUtils.isEmpty(qc.getProIntId())){
			BaseLogUtils.info(logger, "searchAudCreditInfo", "查询信审通过意见失败,缺少必要的的参数条件,项目ID或流程实例ID.DATA:"+JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, BaseExceptionConstant.BASE_EXCEPTION_CODE_604_NAME);
		}
		AudCreditPassOpinionVO audCreditPassOpinionVO = new AudCreditPassOpinionVO();
		List<AudCreditPassOpinionDTO> audCreditPassOpinionDTOList = this.auditApiService.searchAudCreditPassOpinionList(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(CollectionUtils.isNotEmpty(audCreditPassOpinionDTOList)){
			List<AudCreditPassOpinionVO> voList = AudCreditPassOpinionVOTransform.toVOList(audCreditPassOpinionDTOList);
			audCreditPassOpinionVO = voList.get(0);
		}
		//设置价钱前端展示
		if(null!=audCreditPassOpinionVO.getMarketPrice()){
			audCreditPassOpinionVO.setMarketPrice(DecimalUtils.div(audCreditPassOpinionVO.getMarketPrice(), 100));
		}
		if(null!=audCreditPassOpinionVO.getChinaLowestPrice()){
			audCreditPassOpinionVO.setChinaLowestPrice(DecimalUtils.div(audCreditPassOpinionVO.getChinaLowestPrice(), 100));
		}
		if(null!=audCreditPassOpinionVO.getProvinceLowestPrice()){
			audCreditPassOpinionVO.setProvinceLowestPrice(DecimalUtils.div(audCreditPassOpinionVO.getProvinceLowestPrice(), 100));
		}
		if(null!=audCreditPassOpinionVO.getLocalLowestPrice()){
			audCreditPassOpinionVO.setLocalLowestPrice(DecimalUtils.div(audCreditPassOpinionVO.getLocalLowestPrice(), 100));
		}
		if(null!=audCreditPassOpinionVO.getSystemPrice()){
			audCreditPassOpinionVO.setSystemPrice(DecimalUtils.div(audCreditPassOpinionVO.getSystemPrice(), 100));
		}
		
		//设置承租人 担保人 信息
		if(null!=audCreditPassOpinionVO){
			List<AudCreditExtInfoVO> audCreditExtInfoVOList = audCreditPassOpinionVO.getAudCreditExtInfoVOList();
			if(CollectionUtils.isNotEmpty(audCreditExtInfoVOList)){
				for (AudCreditExtInfoVO audCreditExtInfoVO : audCreditExtInfoVOList) {
					if(AudStandingBookConstant.AUD_PASS_EXT_TYP_TENANT.equals(audCreditExtInfoVO.getTypeCd())){//承租人
						audCreditPassOpinionVO.setTenantAudCreditExtInfoVO(audCreditExtInfoVO);
					}else if(AudStandingBookConstant.AUD_PASS_EXT_TYP_GUARANTOR.equals(audCreditExtInfoVO.getTypeCd())){//担保人
						audCreditPassOpinionVO.setGuarantorAudCreditExtInfoVO(audCreditExtInfoVO);
					}
				}
			}
		}
		return audCreditPassOpinionVO;
	}

	//******************************************私有方法*********************************/
	/**
	 * 根据字典中代码组值获取组员集合
	 * @param grpCd 代码组值
	 * @return 集合
	 */
	private List<KeyValueVO> getKvList(String grpCd){
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}
	
	@Override
	public List<KeyValueVO> searchPolicyStandatrdsCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_POLICY_STANDATRDS_CD);
	}

	@Override
	public List<KeyValueVO> searchStandardCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_STANDARD_CD);
	}

	@Override
	public List<KeyValueVO> searchExecuteTemplateCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_EXECUTE_TEMPLATE_CD);
	}

	@Override
	public List<KeyValueVO> searchBuyCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_BUY_CD);
	}

	@Override
	public List<KeyValueVO> searchLesseeAssetsCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_ASSETS_CD);
	}

	@Override
	public List<KeyValueVO> searchCarConfigCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_RELIZE_STATE_CD);
	}

	@Override
	public List<KeyValueVO> searchFinancePlanCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_RELIZE_STATE_CD);
	}

	@Override
	public List<KeyValueVO> searchOperationSituationCdList()
			throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_RELIZE_STATE_CD);
	}

	@Override
	public List<KeyValueVO> searchOperationExperienceCdList()
			throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_OPERATION_EXPERIENCE_CD);
	}

	@Override
	public List<KeyValueVO> searchPaymentSourceCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_OPERATION_EXPERIENCE_CD);
	}

	@Override
	public List<KeyValueVO> searchFulfilCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_FULFIL_CD);
	}

	@Override
	public List<KeyValueVO> searchAttitudeCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_ASSETS_CD);
	}

	@Override
	public List<KeyValueVO> searchManeuverabilityCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_PROCESS_OPINION_CD);
	}

	@Override
	public List<KeyValueVO> searchAssetsProveCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_ASSETS_PROVE_CD);
	}

	@Override
	public List<KeyValueVO> searchRelationshipCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_GRP_RL_TYP_CD);
	}

	/**
	 * TODO 信审通过意见预览
	 */
	@Override
	public String getPreviewString(Long id) throws BaseException {
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "预览通过意见,主键ID不能为空.");
		}
		AudCreditPassOpinionQueryCondition opnQC = new AudCreditPassOpinionQueryCondition();
		opnQC.setId(id);
		List<AudCreditPassOpinionDTO> creditPassOpinionList = this.auditApiService.searchAudCreditPassOpinionList(opnQC, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(CollectionUtils.isNotEmpty(creditPassOpinionList)){
			AudCreditPassOpinionDTO audCreditPassOpinionDTO = creditPassOpinionList.get(0);/**信审通过意见*/
			List<AudCreditExtInfoDTO> audCreditExtInfoDTOList = new ArrayList<AudCreditExtInfoDTO>();
			if(null!=audCreditPassOpinionDTO){
				audCreditExtInfoDTOList = audCreditPassOpinionDTO.getAudCreditExtInfoDTOList();
			}else{
				audCreditPassOpinionDTO = new AudCreditPassOpinionDTO();
			}
			AudCreditExtInfoDTO tenantExtInfo = new AudCreditExtInfoDTO();/**信审维护承租人扩展资料*/
			AudCreditExtInfoDTO guarantorExtInfo = new AudCreditExtInfoDTO();/**信审维护担保人扩展资料*/
			if(CollectionUtils.isNotEmpty(audCreditExtInfoDTOList)){
				for (AudCreditExtInfoDTO audCreditExtInfoDTO : audCreditExtInfoDTOList) {
					if(null!=audCreditExtInfoDTO){
						if(AudStandingBookConstant.AUD_PASS_EXT_TYP_TENANT.equals(audCreditExtInfoDTO.getTypeCd())){
							tenantExtInfo = audCreditExtInfoDTO;
						}else if(AudStandingBookConstant.AUD_PASS_EXT_TYP_GUARANTOR.equals(audCreditExtInfoDTO.getTypeCd())){
							guarantorExtInfo = audCreditExtInfoDTO;
						}
					}
				}
			}
			Long projectId = audCreditPassOpinionDTO.getProjectId();
			PrjBscInfoVO prjBscInfoVO = new PrjBscInfoVO();
			PrjQuatPrpsVO prjQuatPrpsVO = new PrjQuatPrpsVO();
			List<PrjQuatPrpsFeeVO> feeList = new ArrayList<PrjQuatPrpsFeeVO>();
			if(StringUtils.isNotEmpty(projectId)){
				prjBscInfoVO = this.prjBscInfoService.selectById(projectId);/**项目信息*/
				PrjQuatPrpsQueryCondition quatQC = new PrjQuatPrpsQueryCondition();
				quatQC.setIsFormalPrps(BaseConstant.IS_YESNO_YES);
				quatQC.setPrjId(projectId);
				List<PrjQuatPrpsVO> quatList = this.prjQuatPrpsService.searchList(quatQC);
				if(CollectionUtils.isNotEmpty(quatList)){
					prjQuatPrpsVO = quatList.get(0);/**项目报价方案信息*/
					if(null!=prjQuatPrpsVO && null!=prjQuatPrpsVO.getId()){
						PrjQuatPrpsFeeQueryCondition feeQc = new PrjQuatPrpsFeeQueryCondition();
						feeQc.setPrpsId(prjQuatPrpsVO.getId());
						feeList = this.prjQuatPrpsFeeService.searchList(feeQc);/**报价方案费用项信息*/
					}else{
						prjQuatPrpsVO = new PrjQuatPrpsVO();
					}
				}
			}
			Long cstId = null;
			if(null!=prjBscInfoVO){
				cstId = prjBscInfoVO.getCstId();
			}
			CstBscInfoVO cstBscInfoVO = new CstBscInfoVO();
			CstNpBscInfoVO cstNpBscInfoVO = new CstNpBscInfoVO();
			@SuppressWarnings("unused")
			CstCorpBscInfoVO cstCorpBscInfoVO = new CstCorpBscInfoVO();
			CstNpSocialRlVO cstNpSocialRlVO = new CstNpSocialRlVO();
			if(StringUtils.isNotEmpty(cstId)){
				cstBscInfoVO = this.cstBscInfoService.selectDetailById(cstId);/**承租人信息*/
				if(null!=cstBscInfoVO){
					cstNpBscInfoVO = cstBscInfoVO.getCstNpBscInfoVO();/**承租人为自然人,其他信息*/
					if(null!=cstNpBscInfoVO){
						cstNpSocialRlVO = cstNpBscInfoVO.getCstNpSocialRlVO();/**承租人为自然人,配偶信息*/
					}
					cstCorpBscInfoVO = cstBscInfoVO.getCstCorpBscInfoVO();/**承租人为法人,其他信息*/
				}
			}
			/*项目ID+客户关系(担保人)-->项目客户担保人*/
			List<PrjCstBscInfoVO> guarantorList = new ArrayList<PrjCstBscInfoVO>();
			if(StringUtils.isNotEmpty(projectId)){
				PrjCstBscInfoQueryCondition guarantorQC = new PrjCstBscInfoQueryCondition();
				guarantorQC.setPrjId(Long.valueOf(projectId));
				guarantorQC.setCstRlTyp(PrjCstBscInfoConstant.CST_Rl_ATTR_GUARANTOR);
				guarantorList = this.prjCstBscInfoService.searchList(guarantorQC);
			}
			//CstBscInfoVO guarantorCstBscInfoVO = new CstBscInfoVO();
			PrjCstBscInfoVO guarantorVO = new PrjCstBscInfoVO();
			if(CollectionUtils.isNotEmpty(guarantorList)){
				guarantorVO = guarantorList.get(0);
				/*Long cstId2 = guarantorVO.getCstId();
				guarantorCstBscInfoVO = this.cstBscInfoService.selectDetailById(cstId2);*//**担保人信息*/
			}else{
				guarantorVO = null;
			}
			StringBuffer previewString = new StringBuffer();
			previewString.append("一：信审资料及承租人资质</br>");
			/**判断承租人类型*/
			if(CustomerConstant.CST_TYP_CD_NP.equals(cstBscInfoVO.getCstTypCd())){	//自然人
				previewString.append("&nbsp;&nbsp;&nbsp;1、承租人"+cstBscInfoVO.getCstNm()+cstNpBscInfoVO.getMarStsCdNm()+"，"+cstNpSocialRlVO.getRlNm()+"，");
				if(StringUtils.isNotEmpty(tenantExtInfo.getCreditInfo())){
					previewString.append("提供的信审资料"+tenantExtInfo.getCreditInfo()+"；</br>");
				}else{
					previewString.append("提供的信审资料真实齐全合规；</br>");
				}
				previewString.append("&nbsp;&nbsp;&nbsp;2、承租人"+cstNpBscInfoVO.getMarStsCdNm()+"，");
				if(StringUtils.isNotEmpty(tenantExtInfo.getQualificationsInfo())){
					previewString.append("资质"+tenantExtInfo.getQualificationsInfo()+"，");
				}else{
					previewString.append("资质合规，");
				}
				if(StringUtils.isNotEmpty(tenantExtInfo.getAssetsProveCdNm())){
					previewString.append("提供"+tenantExtInfo.getAssetsProveCdNm()+"作为资产证明，");
				}else{
					previewString.append("未提供资产证明，");
				}
				if(StringUtils.isNotEmpty(tenantExtInfo.getResearchReport())){
					previewString.append("调查报告显示"+tenantExtInfo.getResearchReport()+"；</br>");
				}
				else{
					previewString.append("</br>");
				}
			}else{	//法人
				previewString.append("&nbsp;&nbsp;&nbsp;1、承租人"+cstBscInfoVO.getCstNm()+"，");
				if(StringUtils.isNotEmpty(tenantExtInfo.getCreditInfo())){
					previewString.append("提供的信审资料"+tenantExtInfo.getCreditInfo()+"；</br>");
				}else{
					previewString.append("提供的信审资料真实齐全合规；</br>");
				}
				previewString.append("&nbsp;&nbsp;&nbsp;2、承租人");
				if(null!=tenantExtInfo.getRegisterTm()){
					previewString.append("注册时间为"+DateUtils.formatDateToString(tenantExtInfo.getRegisterTm(), DateUtils.YYYY_MM_DD)+"，");
				}
				if(StringUtils.isNotEmpty(tenantExtInfo.getBusiness())){
					previewString.append("主要从事业务"+tenantExtInfo.getBusiness()+"，");
				}
				if(StringUtils.isNotEmpty(tenantExtInfo.getQualificationsInfo())){
					previewString.append("资质"+tenantExtInfo.getQualificationsInfo()+"，");
				}else{
					previewString.append("资质合规，");
				}
				if(StringUtils.isNotEmpty(tenantExtInfo.getAssetsProveCdNm())){
					previewString.append("提供"+tenantExtInfo.getAssetsProveCdNm()+"作为资产证明");
				}else{
					previewString.append("未提供资产证明");
				}
				if(StringUtils.isNotEmpty(tenantExtInfo.getResearchReport())){
					previewString.append("，调查报告显示"+tenantExtInfo.getResearchReport()+"；</br>");
				}else{
					previewString.append("；</br>");
				}
			}
			//=========================================================================================
			if(null!=guarantorVO){
				previewString.append("&nbsp;&nbsp;&nbsp;3、担保人"+guarantorVO.getCstNm()+"与承租人关系"+guarantorExtInfo.getRelationshipCdNm()+"，");
				if(StringUtils.isNotEmpty(guarantorExtInfo.getCreditInfo())){
					previewString.append("提供的信审资料"+guarantorExtInfo.getCreditInfo()+"；</br>");
				}else{
					previewString.append("提供的信审资料真实齐全合规；</br>");
				}
				if(StringUtils.isNotEmpty(guarantorExtInfo.getQualificationsInfo())){
					previewString.append("资质"+guarantorExtInfo.getQualificationsInfo()+"，");
				}else{
					previewString.append("资质合规，");
				}
				if(StringUtils.isNotEmpty(guarantorExtInfo.getAssetsProveCdNm())){
					previewString.append("提供"+guarantorExtInfo.getAssetsProveCdNm()+"作为资产证明");
				}else{
					previewString.append("未提供资产证明");
				}
				if(StringUtils.isNotEmpty(guarantorExtInfo.getResearchReport())){
					previewString.append("，调查报告显示"+guarantorExtInfo.getResearchReport()+"；</br>");
				}else{
					previewString.append("；</br>");
				}
				previewString.append("&nbsp;&nbsp;&nbsp;4、");
			}else{
				previewString.append("&nbsp;&nbsp;&nbsp;3、");
			}
			//==========================================================================================
			if(StringUtils.isNotEmpty(tenantExtInfo.getTimes())){
				previewString.append("此次为第"+tenantExtInfo.getTimes()+"次在我司融资，");
			}else{
				previewString.append("此次为第0次在我司融资，");
			}
			if(StringUtils.isNotEmpty(tenantExtInfo.getBadRecordInfo())){
				previewString.append("不良信用记录"+tenantExtInfo.getBadRecordInfo()+"，");
			}else{
				previewString.append("无不良信用记录，");
			}
			if(StringUtils.isNotEmpty(tenantExtInfo.getCourtsEnforceInfo())){
				previewString.append("法院执行情况"+tenantExtInfo.getCourtsEnforceInfo()+";");
			}else{
				previewString.append("无法院执行情况；");
			}
			//===========================================================================================
			previewString.append("</br>二：产品政策</br>&nbsp;&nbsp;&nbsp;");
			/**判断模板*/
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getExecuteTemplateCd())){
				if("1".equals(audCreditPassOpinionDTO.getExecuteTemplateCd())){	//模板一
					previewString.append(prjBscInfoVO.getBuOrgCdNm()+"业务，代理商类型为"+prjBscInfoVO.getAgntTypCdNm()+"，业务类型为"+prjBscInfoVO.getBizTypCdNm()+"，");
					previewString.append("项目类型为"+prjBscInfoVO.getPrjTypCdNm()+"，业务来源为"+prjBscInfoVO.getBizResCdNm()+"，");
					previewString.append("融资期限"+prjQuatPrpsVO.getLsPd()+prjQuatPrpsVO.getLsPdUntCdNm()+"，");
					previewString.append("月还款"+DecimalUtils.div(prjQuatPrpsVO.getEachEstRntAmt(), 100)+"，");
					previewString.append("收益率"+audCreditPassOpinionDTO.getReturnPct()+"，");
					previewString.append("执行政策标准"+audCreditPassOpinionDTO.getPolicyStandatrdsCdNm());
					if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getStandardCdNm())){
						previewString.append("，"+audCreditPassOpinionDTO.getStandardCdNm()+"。");
					}else{
						previewString.append("。");
					}
				}else{//模板二
					previewString.append(prjBscInfoVO.getBuOrgCdNm()+"业务，代理商类型为"+prjBscInfoVO.getAgntTypCdNm()+"，业务类型为"+prjBscInfoVO.getBizTypCdNm()+"，");
					previewString.append("项目类型为"+prjBscInfoVO.getPrjTypCdNm()+"，业务来源为"+prjBscInfoVO.getBizResCdNm()+"，");
					previewString.append("融资方案为"+prjQuatPrpsVO.getPrpsCfgNm()+"，融资期限为"+prjQuatPrpsVO.getLsPd()+prjQuatPrpsVO.getLsPdUntCdNm());
					if(CollectionUtils.isNotEmpty(feeList)){
						for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : feeList) {
							if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_CONSULT_1)){//咨询费1
								previewString.append("咨询费1"+DecimalUtils.div(prjQuatPrpsFeeVO.getFeeAmt(), 100)+"，");
							}else if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_CONSULT_2)){//咨询费2
								previewString.append("咨询费2"+DecimalUtils.div(prjQuatPrpsFeeVO.getFeeAmt(), 100)+"，");
							}else if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_PURCHASE)){//留购价
								previewString.append("留购价"+DecimalUtils.div(prjQuatPrpsFeeVO.getFeeAmt(), 100)+"，");
							}
						}
					}
					previewString.append("年利率"+prjQuatPrpsVO.getAnnIntRatePct()+"，");
					previewString.append("月还款"+DecimalUtils.div(prjQuatPrpsVO.getEachEstRntAmt(), 100)+"，");
					previewString.append("收益率"+audCreditPassOpinionDTO.getReturnPct()+"，");
					previewString.append("执行政策标准"+audCreditPassOpinionDTO.getPolicyStandatrdsCdNm());
					if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getStandardCdNm())){
						previewString.append("，"+audCreditPassOpinionDTO.getStandardCdNm()+"。");
					}else{
						previewString.append("。");
					}
				}
			}
			//===========================================================================================
			PrjPrdDtlQueryCondition prjPrdDtlQC = new PrjPrdDtlQueryCondition();
			prjPrdDtlQC.setPrjId(projectId);
			List<PrjPrdDtlVO> prjPrdDtlVOList = this.prjPrdDtlService.selectList(prjPrdDtlQC);/**项目产品明细列表*/
			previewString.append("</br>三：上户</br>&nbsp;&nbsp;&nbsp;");
			List<String> companyNmList = new ArrayList<String>();
			String companyNmString = "";
			if(CollectionUtils.isNotEmpty(prjPrdDtlVOList)){
				for (PrjPrdDtlVO prjPrdDtlVO : prjPrdDtlVOList) {
					if(null!=prjPrdDtlVO && !companyNmList.contains(prjPrdDtlVO.getLnkCompNm()) && null!=prjPrdDtlVO.getLnkCompNm()){
						companyNmList.add(prjPrdDtlVO.getLnkCompNm());
					}
				}
				if(CollectionUtils.isNotEmpty(companyNmList)){
					for (String string : companyNmList) {
						companyNmString+=string;
						companyNmString+="，";
					}
					previewString.append("上公司户,挂靠公司为"+companyNmString);
				}else{
					previewString.append("上个人户");
				}
			}
			//===========================================================================
			PrjPrdBscInfoQueryCondition prjPrdBscQC = new PrjPrdBscInfoQueryCondition();
			prjPrdBscQC.setPrjId(projectId);
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = this.prjPrdBscInfoService.searchList(prjPrdBscQC);
			previewString.append("</br>四：核价</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("融资数量为");
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					if(null!=prjPrdBscInfoVO){
						previewString.append(prjPrdBscInfoVO.getPrdQty()+prjPrdBscInfoVO.getPrdNm()+"，");
					}
				}
			}
			previewString.append("合同总额"+prjQuatPrpsVO.getContAmt()+"，");
			//===========================================================================
			previewString.append("</br>五：运营分析</br>&nbsp;&nbsp;&nbsp;");
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getOperationAnalysis())){
				previewString.append(audCreditPassOpinionDTO.getOperationAnalysis());
			}
			//===========================================================================
			previewString.append("</br>六：信审员评价</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("1、意愿：");
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getBuyCdNm())){
				previewString.append("承租人购车行为"+audCreditPassOpinionDTO.getBuyCdNm()+"，");
			}
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getAttitudeCdNm())){
				previewString.append("回访态度"+audCreditPassOpinionDTO.getAttitudeCdNm()+"。");
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			if(CustomerConstant.CST_TYP_CD_NP.equals(cstBscInfoVO.getCstTypCd())){	//自然人
				previewString.append("2、家庭资产状况：");
				if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getLesseeAssetsCdNm())){
					previewString.append("从提供资产情况来看，承租人资产实力"+audCreditPassOpinionDTO.getLesseeAssetsCdNm());
				}
			}else{
				previewString.append("2、公司经营状况：");
				if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getGuarantorAssetsCd2Nm())){
					previewString.append("从提供财务报表来看，担保人资产实力"+audCreditPassOpinionDTO.getGuarantorAssetsCd2Nm());
				}
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("3、电话回访反馈：");
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getCarConfigCdNm())
					||StringUtils.isNotEmpty(audCreditPassOpinionDTO.getFinancePlanCdNm())
					||StringUtils.isNotEmpty(audCreditPassOpinionDTO.getOperationSituationCdNm())
					||StringUtils.isNotEmpty(audCreditPassOpinionDTO.getOperationExperienceCdNm())
					||StringUtils.isNotEmpty(audCreditPassOpinionDTO.getPaymentSourceCdNm())){
				previewString.append("承租人");
			}
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getCarConfigCdNm())){
				previewString.append(audCreditPassOpinionDTO.getCarConfigCdNm()+"车辆配置，");
			}
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getFinancePlanCdNm())){
				previewString.append(audCreditPassOpinionDTO.getFinancePlanCdNm()+"融资方案，");
			}
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getOperationSituationCdNm())){
				previewString.append("对车辆运营情况"+audCreditPassOpinionDTO.getOperationSituationCdNm()+"，");
			}
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getOperationExperienceCdNm())){
				previewString.append(audCreditPassOpinionDTO.getOperationExperienceCdNm()+"运营经验，");
			}
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getPaymentSourceCdNm())){
				previewString.append(audCreditPassOpinionDTO.getPaymentSourceCdNm()+"第二还款来源。");
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("4、风险:");
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getRiskAnalysis())){
				previewString.append(audCreditPassOpinionDTO.getRiskAnalysis());
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("5、可操作性评价：");
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getManeuverabilityCdNm())){
				previewString.append(audCreditPassOpinionDTO.getManeuverabilityCdNm());
			}
			previewString.append("</br>");
			previewString.append("备注:</br>&nbsp;&nbsp;&nbsp;");
			if(StringUtils.isNotEmpty(audCreditPassOpinionDTO.getOtherInfo())){
				previewString.append(audCreditPassOpinionDTO.getOtherInfo());
			}
			return previewString.toString();
		}
		return "";
	}
	
	
	
	
	
	
	
}
